package main

import (
	"log"
	"os"
	"os/signal"
	"syscall"
)

var taskSet map[string]*SyncTask = make(map[string]*SyncTask, 0)

func main() {
	src, err := CreateRedisSrc("127.0.0.1:30001", "")
	if err != nil {
		log.Fatalf("create src err:%v", err)
	}

	dst, err := CreateRedisDst("127.0.0.1:40011", "")
	if err != nil {
		log.Fatalf("create dst err:%v", err)
	}

	task := NewSyncTask(src, dst)
	if _, exist := taskSet[task.id]; exist {
		log.Fatalf("exist task id:%s", task.id)
	} else {
		taskSet[task.id] = task
	}
	go func ()  {
		log.Fatal(task.Start())
	}()


	sigCh := make(chan os.Signal, 1)
	signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
	sig := <-sigCh
	log.Printf("Got signal [%s] to exit.", sig)

	for _, t := range taskSet {
		t.Stop()
	}

}